/**
 * SPDX-FileCopyrightText: 2023-2025 Sangfor Technologies Inc.
 * SPDX-License-Identifier: Mulan PSL v2
 */
<template>
    <div class="my-dataset-page">
        <dataset-empty v-if="hideTableList"/>
        <dataset-list v-else
                      :data="tableData"
                      @get-list="search"/>
    </div>
</template>

<script>
import store from 'src/vuex/store';
import DatasetEmpty from "./components/dataset_empty";
import DatasetList from "./components/dataset_list";

let userID = store.state.userId;

const PAGE_COUNT = 20;

const DATASET_URL = {
    get: '/ai-datalake/api/v1/datasets'
}
export default {
    components: {
        DatasetEmpty,
        DatasetList
    },
    data() {
        return {
            tableData: {},
            searchParams: {
                page: 1,  // 查询第几页的数据，默认第一页
                pageSize: PAGE_COUNT,  // 每页展示多少条
                queryType: 'all',
                searchKeyword: '',
                username: userID,
            },
            isSearch: false,
            isFirstLoading: true,
        }
    },
    computed: {
        hideTableList() {
            return (this.tableData.list || []).length === 0 && !this.isFirstLoading && !this.isSearch
        }
    },
    async mounted() {
        await this.getList()
    },
    methods: {
        search(searchParams) {
            this.searchParams = searchParams;
            this.isSearch = true;
            this.getList();
        },
        async getList() {
            let jsonData = await this.$ajax.get(`${DATASET_URL.get}`, this.searchParams);
            let {success, msg, data} = jsonData;
            if (!success) {
                this.$showErr(msg || _('加载数据失败'));
                return;
            }
            this.isFirstLoading = false;
            this.tableData = data;
        }
    }
};
</script>

<style lang="less" scoped>
.my-dataset-page {
    width: 100%;
    height: 100%;
}
</style>
